﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.Http.Controllers;

namespace NCS.IConnect.Core.WebApi.Validation
{
    /// <summary>
    /// This kinds of attributes are used for conditional validation.
    /// </summary>
    public abstract class ConditionalValidationAttribute : Attribute
    {
        /// <summary>
        /// Gets or sets an error message to associate with a validation control if validation fails.
        /// </summary>
        public string ErrorMessage { get; set; }

        /// <summary>
        /// Gets or sets the error message resource name to use in order to look up the System.ComponentModel.DataAnnotations.ValidationAttribute.ErrorMessageResourceType property value if validation fails.
        /// </summary>
        public string ErrorMessageResourceName { get; set; }

        /// <summary>
        /// Gets or sets the resource type to use for error-message lookup if validation fails.
        /// </summary>
        public Type ErrorMessageResourceType { get; set; }

        /// <summary>
        /// Create a <see cref="ValidationAttribute"/> to perform validation.
        /// </summary>
        /// <returns>The created <see cref="ValidationAttribute"/>.</returns>
        public abstract ValidationAttribute CreateValidationAttribute();

        /// <summary>
        /// Determine whether to perform validation.
        /// </summary>
        /// <param name="actionContext">The current <see cref="HttpActionContext"/>.</param>
        /// <returns>A <see cref="bool"/> value indicating whether to perform validation.</returns>
        public abstract bool WillValidate(HttpActionContext actionContext);

    }
}